package cn.aiyaun;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @author wangyuan
 * @date 2021/8/23
 */
public class BufferTest2 {

    public static void main(String[] args) throws Exception {
        String s = "aiyuan";
        FileOutputStream outputStream = new FileOutputStream("D:\\environment\\IdeaProjects\\springboot-aiyuan\\noi-test\\src\\main\\resources\\2.txt");
        FileChannel channel = outputStream.getChannel();

        ByteBuffer allocate = ByteBuffer.allocateDirect(1024);
        allocate.put(s.getBytes());
        allocate.flip();
        channel.write(allocate);
        channel.close();
        outputStream.close();



    }

}
